import java.awt.BasicStroke;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;

import javax.swing.JPanel;
import javax.swing.Timer;

public class AnimationJPanel extends JPanel {
	private Color mouthColor = Color.black;
	private Timer timer;
	private ArmMovement arms;
	private final int RATE = 500;

	public AnimationJPanel(int i, int j) {
		arms = new ArmMovement();

		AnimationCalculations AC = new AnimationCalculations(this, arms);
		timer = new Timer(RATE, AC);
		 timer.start();

		// TODO Auto-generated constructor stub
	}

	public void paintComponent(Graphics g) {
		super.paintComponent(g);

		Graphics2D g2d = (Graphics2D) g;
		 Toolkit.getDefaultToolkit().sync();
		// drawComputerMove(g2d);
		// drawMessage(g2d);

		arms.drawArms(g2d);
		
		// arms.testDraw(g2d);
		 
		 drawBody(g2d);
		
		 Toolkit.getDefaultToolkit().sync();
		g.dispose();
	}

	private void drawBody(Graphics2D g2d) {
		// Draw Rectangle
		/*
		 * Rectangle rect = new Rectangle (10,10,100,100);
		 * g2d.setColor(Color.black); g2d.fill(rect);
		 * 
		 * //Draw Line Line2D.Double line = new Line2D.Double (0,0,500,500);
		 * g2d.setColor(Color.red); Stroke s = new BasicStroke(20);
		 * g2d.setStroke(s); g2d.drawLine(0,0,500,500);
		 */

		// Draw circle
		/*
		 * Ellipse2D.Double armleft = new Ellipse2D.Double(234,265,35,30);
		 * 
		 * g2d.setColor(Color.black); g2d.fill(armleft);
		 * 
		 * 
		 * 
		 * for (double q=0;q<1;q += 0.001) { g2d.fill(rotateShape(armleft, q,
		 * 264, 270)); } Ellipse2D.Double armright = new
		 * Ellipse2D.Double(330,265,35,30);
		 * 
		 * g2d.setColor(Color.black); g2d.fill(armright);
		 * 
		 * for (double q=0;q>-1;q -= 0.001) { g2d.fill(rotateShape(armright, q,
		 * 330, 270)); }
		 */
		// /////////////////////////////////////////
		Ellipse2D.Double legleft = new Ellipse2D.Double(223, 310, 45, 40);

		g2d.setColor(Color.black);
		g2d.fill(legleft);

		Ellipse2D.Double legright = new Ellipse2D.Double(330, 310, 45, 40);

		g2d.setColor(Color.black);
		g2d.fill(legright);

		// /////////////////////////////////////////
		Ellipse2D.Double body = new Ellipse2D.Double(250, 250, 100, 100);

		g2d.setColor(Color.black);
		g2d.fill(body);

		Ellipse2D.Double belly = new Ellipse2D.Double(265.5, 260, 70, 70);

		g2d.setColor(Color.white);
		g2d.fill(belly);

		// //////////////////////////////////////////////
		Ellipse2D.Double earleft = new Ellipse2D.Double(245, 170, 25, 25);

		g2d.setColor(Color.black);
		g2d.fill(earleft);

		Ellipse2D.Double earright = new Ellipse2D.Double(330, 170, 25, 25);

		g2d.setColor(Color.black);
		g2d.fill(earright);

		// //////////////////////////////////////////////////////////
		Ellipse2D.Double headborder = new Ellipse2D.Double(250, 170, 101, 101);

		g2d.setColor(Color.black);
		g2d.fill(headborder);

		Ellipse2D.Double head = new Ellipse2D.Double(252.5, 171.8, 96, 96);

		g2d.setColor(Color.white);
		g2d.fill(head);
		// /////////////////////////////////////////////////////////////////
		Ellipse2D.Double eyespotleft = new Ellipse2D.Double(258, 187, 30, 52);

		g2d.setColor(Color.black);
		g2d.fill(eyespotleft);

		Ellipse2D.Double eyespotright = new Ellipse2D.Double(312, 187, 30, 52);

		g2d.setColor(Color.black);
		g2d.fill(eyespotright);

		// ///////////////////////////////
		Ellipse2D.Double eyeleft = new Ellipse2D.Double(264, 210, 14, 18);

		g2d.setColor(Color.white);
		g2d.fill(eyeleft);

		Ellipse2D.Double eyesright = new Ellipse2D.Double(318, 210, 14, 18);

		g2d.setColor(Color.white);
		g2d.fill(eyesright);

		// ///////////////////////////////
		Arc2D.Double mouthbottom = new Arc2D.Double(293, 230, 15, 15, 180, 180,
				Arc2D.CHORD);

		g2d.setColor(mouthColor);
		g2d.fill(mouthbottom);
		/*
		 * for (double i=0;i<1;i += 0.001) { g2d.fill(rotateShape(armright, i,
		 * 60, 60)); }
		 */
		
		//evil eyes
		
	}

	public static Shape rotateShape(final Shape base, final double angle,
			final float x, final float y) {
		if (base == null) {
			return null;
		}
		final AffineTransform rotate = AffineTransform.getRotateInstance(angle,
				x, y);
		final Shape result = rotate.createTransformedShape(base);
		return result;
	}

	public Color getMouthColor() {
		return mouthColor;
	}

	public void setMouthColor(Color color) {
		this.mouthColor = color;
	}

	public ArmMovement getArms() {
		return arms;
	}

	public void setArms(ArmMovement arms) {
		this.arms = arms;
	}

}
